const roomMixin = {
  data() {
    return {};
  },
  computed: {
    // 计算每月的天数
    getDayNum: function () {
      const year = this.$moment(this.year).format("YYYY");
      const month = this.$moment(this.year).format("MM");
      const num = new Date(year, month, 0);
      return num.getDate();
    }
  },
  // created() {},
  // mounted() {},
  methods: {
    // 遍历转换数据
    transformData(data) {
      const n = data.length;
      for (let i = 0; i < n; i++) {
        data[i].date = this.dayList(data[i].date);
      }
      return data;
    },
    // 筛选日期，把非匹配到的日期填充
    dayList(data) {
      const n = this.getDayNum;
      const day = [];
      for (let i = 0; i < n; i++) {
        for (let j = 0; j < data.length; j++) {
          if (this.$moment(data[j].day).format("DD") == i + 1) {
            day[i] = data[j];
            break;
          } else {
            day[i] = {
              day: `${this.$moment(data[j].day).format("YYYY-MM")}-${(i + 1).toString().padStart(2, "0")}`,
              status: false
            };
          }
        }
      }
      return day;
    }
  }
};
export default roomMixin;
